package com.nanbei.a14;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @ClassDescription: Cglib 代理的实现
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/11/18 15:51
 */
public class A14 {
    public static void main(String[] args) {
        Target target = new Target();
        Proxy proxy = new Proxy(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                System.out.println("before......");
                //Object invoke = method.invoke(target, objects);

                // FastClass
                // Object invoke = methodProxy.invoke(target, objects); // 内部无反射，结合目标用
                Object invoke = methodProxy.invokeSuper(o, objects); // 内部无反射，结合代理用
                return invoke;
            }
        });
        proxy.save();
        proxy.save(1);
        proxy.save(2L);
    }
}
